package com.chb.queue;

import java.util.Stack;

/**
 * 面试题09. 用两个栈实现队列
 * https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
 */
class CQueue {
    private Stack<Integer> inStack = new Stack<Integer>();
    private Stack<Integer> outStack = new Stack<Integer>();

    public CQueue() {

    }
    
    public void appendTail(int value) {
        inStack.push(value);
    }
    
    public int deleteHead() {
        if (inStack.empty()) return -1;
        while(!inStack.empty()) {
            outStack.push(inStack.pop());
        }
        int retVal = outStack.pop();
        while(!outStack.empty()) {
            inStack.push(outStack.pop());
        }
        return retVal;
    }
}